package com.usian.controller;

import com.usian.pojo.Emp;
import com.usian.service.EmpService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.cloud.context.config.annotation.RefreshScope;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
@RequestMapping("/provider")
@RefreshScope //动态从nacos配置中心获取最新值
public class EmpController {

    @Value("${config.info}")
    private String configInfo;



    @Autowired
    private EmpService empService;

    @RequestMapping("findAll")
    public List<Emp> findAll(){
        System.out.println("读取值："+configInfo);
        return empService.findAll();
    }

    @GetMapping("findById/{id}")
    public Emp findById(@PathVariable int id) {
        return empService.findById(id);
    }

    @GetMapping("findByIdAndName/{id}/{name}")
    public Emp findByIdAndName(@PathVariable int id, @PathVariable String name) {
        return empService.findByIdAndName(id, name);
    }

}
